export default {
    namespaced: true,
    state: {
        //历史导航栏地址
        tagViewPathData: []
    },
    mutations: {
        //修改数据
        updateTagViewPath(state, item) {
            let indexof = -1
            state.tagViewPathData.forEach((element, index) => {
                element.isTrue = false
                if (element.id == item.id) {
                    indexof = index
                }
            });
            if (indexof < 0) {
                state.tagViewPathData.push({
                    ...item,
                    isTrue: true
                })
            } else {
                state.tagViewPathData[indexof].isTrue = true
            }

            window.sessionStorage.setItem('tagViewPath', JSON.stringify(state.tagViewPathData))
        },
        //初始化数据
        initTagViewPath(state) {
            state.tagViewPathData = JSON.parse(window.sessionStorage.getItem('tagViewPath')) || []
        },
        //删除数据
        delTagViewPath(state, item) {
            state.tagViewPathData = state.tagViewPathData.filter(it => it.id != item.id)
            window.sessionStorage.setItem('tagViewPath', JSON.stringify(state.tagViewPathData))
        },
    },
    actions: {

    },
    getters: {
        //获取激活路径
        getActivePath(state) {
            return state.tagViewPathData.filter(it => it.isTrue)[0] ? state.tagViewPathData.filter(it => it.isTrue)[0].path : ''
        }
    }
}